namespace Ray.Web.Controllers
{
    using System.Collections.Generic;
    using Castle.MonoRail.Framework;
    using Castle.MonoRail.Framework.Helpers;
    using Castle.MonoRail.ActiveRecordSupport;

    using System;
    using Ray.Web.Models;

    [Rescue("generalerror"), Layout("Pagination")]
    public class PaginationController : SmartDispatcherController
    {
        public void List()
        {
            PropertyBag["items"] = PaginationHelper.CreatePagination(this, PerformSearch(), 3);
        }

        //private IList ObtainMyLargeCollection()
        //{

        //}

        public IList<Ray_Master> PerformSearch()
        {
            // Do your actual search

            return (IList<Ray_Master>)Ray_Master.FindAll();
        }
        public void Search(String make, String model, String year)
        {
            // create the pagination

            //PropertyBag["Cars"] = PaginationHelper.CreateCachedPagination(
            //    "carssearchkey" + this.make + this.model + this.year,
            //    5, new DataObtentionDelegate(PerformSearch));
        }

        public void New()
        {
        }

        [AccessibleThrough(Verb.Post)]
        public void Create([ARDataBind("ray_master", AutoLoadBehavior.OnlyNested)] Ray_Master ray_master)
        {
            try
            {
                ray_master.Create();

                RedirectToAction("list");
            }
            catch (Exception ex)
            {
                Flash["errormessage"] = ex.Message;
                Flash["ray_master"] = ray_master;

                RedirectToAction("new");
            }
        }

        public void Edit(int id)
        {
            if (!Flash.Contains("ray_master"))
            {
                PropertyBag["ray_master"] = Ray_Master.Find(id);
            }
        }

        [AccessibleThrough(Verb.Post)]
        public void Update([ARDataBind("ray_master", AutoLoadBehavior.Always)] Ray_Master ray_master)
        {
            try
            {
                ray_master.Create();

                RedirectToAction("List");
            }
            catch (Exception ex)
            {
                Flash["errormessage"] = ex.Message;
                Flash["ray_master"] = ray_master;

                RedirectToAction("Edit", "id" + ray_master.Id);
            }
        }

        public void ConfirmDelete([ARFetch("id", false, true)] Ray_Master ray_master)
        {
            PropertyBag["ray_master"] = ray_master;
        }

        [AccessibleThrough(Verb.Post)]
        public void Delete([ARFetch("ray_master.id", false, true)] Ray_Master ray_master)
        {
            try
            {
                ray_master.Delete();

                RedirectToAction("List");
            }
            catch (Exception ex)
            {
                Flash["errormessage"] = ex.Message;

                RedirectToAction("ConfirmDelete", "id" + ray_master.Id);
            }
        }




        public void Index1()
        {
            PropertyBag["items"] = PaginationHelper.CreatePagination<Ray_Master>(this, PerformSearch(), 10);
        }
        public void Index2()
        {
            PropertyBag["items"] = PaginationHelper.CreatePagination<Ray_Master>(this, PerformSearch(), 10);
        }
        public void Index3()
        {
            PropertyBag["items"] = PaginationHelper.CreatePagination<Ray_Master>(this, PerformSearch(), 10);
        }
        public void Index4()
        {
            PropertyBag["items"] = PaginationHelper.CreatePagination<Ray_Master>(this, PerformSearch(), 10);
        }
        public void Index5()
        {
            PropertyBag["items"] = PaginationHelper.CreatePagination<Ray_Master>(this, PerformSearch(), 10);
        }
        public void Index6()
        {
            PropertyBag["items"] = PaginationHelper.CreatePagination<Ray_Master>(this, PerformSearch(), 10);
        }
        public void Index7()
        {
            PropertyBag["items"] = PaginationHelper.CreatePagination<Ray_Master>(this, PerformSearch(), 10);
        }
        public void Index8()
        {
            PropertyBag["items"] = PaginationHelper.CreatePagination<Ray_Master>(this, PerformSearch(), 10);
        }
        public void Index9()
        {
            PropertyBag["items"] = PaginationHelper.CreatePagination<Ray_Master>(this, PerformSearch(), 10);
        }


        //Property for paging
        //* FirstIndex
        //* CurrentIndex
        //* LastIndex
        //* PreviousIndex
        //* NextIndex
        //* HasPrevious
        //* HasNext
        //* HasFirst
        //* HasLast
        //* FirstItem
        //* LastItem
        //* TotalItems
    }

    [Crud(typeof(Ray_Master))]
    [DynamicActionProvider(typeof(CrudActionProvider))]
    [Layout("default"), Rescue("generalerror")]
    public class Category2Controller : ARSmartDispatcherController
    {

    }
}
